package com.nhncorp.pleiades.msg;

import java.io.IOException;

public class ParserFactory {

  public enum PARSER_TYPE {
     NEPTUNE_MASTER, EVENT_MANAGER
  };
  static String packageName = System.getProperty("message_template_package",
      MessageParser.class.getPackage().getName());

  public static MessageParser newInstance() throws IOException {
    return newInstance(PARSER_TYPE.NEPTUNE_MASTER);
  }

  public static MessageParser newInstance(PARSER_TYPE type) throws IOException {
    try {
      String className= NeptuneMessageParser.class.getSimpleName();
      if(type == PARSER_TYPE.EVENT_MANAGER) {
        className = EventMessageParser.class.getSimpleName();
      }
      return (MessageParser) Class.forName(packageName + "." + className)
          .newInstance();
    } catch (InstantiationException e) {
      throw new IOException(e.getMessage());
    } catch (IllegalAccessException e) {
      throw new IOException(e.getMessage());
    } catch (ClassNotFoundException e) {
      throw new IOException(e.getMessage());
    }
  }
}
